package com.ld.control.business.task.controller;


import com.ld.control.business.task.service.TaskTmpService;
import com.ld.control.business.task.vo.req.ConfigProcessTmpReqVo;
import com.ld.control.business.task.vo.req.DragSortReqVo;
import com.ld.control.business.task.vo.req.TaskTmpReqVo;
import com.ld.control.business.task.vo.resp.TaskTmpRespVo;
import com.ld.control.common.ResultResponse;
import com.ld.control.common.vo.GeneratePageListVo;
import com.ld.control.sysenum.ResultResponseEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 任务模板表 前端控制器
 * </p>
 *
 * @author wangfeng
 * @since 2024-05-09
 */
@Slf4j
@Tag(name = "任务模板相关接口")
@RestController
public class TaskTmpController {

    @Autowired
    private TaskTmpService taskTmpService;

    @GetMapping("/api/centralControl/taskTmp/getList")
    @Operation(summary = "任务模板列表")
    public ResultResponse<GeneratePageListVo<TaskTmpRespVo>> getPageList(
            @RequestParam(required = false) String name,
            @RequestParam(required = false, defaultValue = "1") Integer current,
            @RequestParam(required = false, defaultValue = "10") Integer size
            ) {
        GeneratePageListVo<TaskTmpRespVo> pageList = taskTmpService.getPageList(name, current, size);
        return ResultResponse.success(pageList);
    }

    @GetMapping("/api/centralControl/taskTmp/getById")
    @Operation(summary = "查询任务模板详情")
    public ResultResponse<TaskTmpRespVo> getById(
            @RequestParam Long id
    ) {
        TaskTmpRespVo taskTmpRespVo = taskTmpService.getById(id);
        return ResultResponse.success(taskTmpRespVo);
    }

    @PostMapping("/api/centralControl/taskTmp/add")
    @Operation(summary = "添加任务模板")
    public ResultResponse<ResultResponseEnum> add(
            @RequestBody TaskTmpReqVo reqVo
    ) {
        taskTmpService.add(reqVo);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/taskTmp/update")
    @Operation(summary = "修改任务模板")
    public ResultResponse<ResultResponseEnum> update(
            @RequestBody TaskTmpReqVo reqVo
    ) {
        taskTmpService.update(reqVo);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/taskTmp/deleteById")
    @Operation(summary = "修删除任务模板")
    public ResultResponse<ResultResponseEnum> deleteById(
            @RequestParam Long id
    ) {
        taskTmpService.deleteById(id);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/taskTmp/configProcessTmp")
    @Operation(summary = "任务配置流程模板")
    public ResultResponse<ResultResponseEnum> configProcessTmp(
            @RequestBody ConfigProcessTmpReqVo reqVo
    ) {
        taskTmpService.configProcessTmp(reqVo);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/taskTmp/deleteProcessTmp")
    @Operation(summary = "删除任务配置流程模板")
    public ResultResponse<ResultResponseEnum> deleteProcessTmp(
            @RequestParam Long taskProcessTmpId
    ) {
        taskTmpService.deleteProcessTmp(taskProcessTmpId);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/taskTmp/dragSort")
    @Operation(summary = "拖拽排序")
    public ResultResponse<ResultResponseEnum> dragSort(
            @RequestBody DragSortReqVo reqVo
    ) {
        taskTmpService.dragSort(reqVo);
        return ResultResponse.success();
    }


}

